package org.openspml.providers.one_c.clients;

import org.openspml.client.SpmlClient;
import org.openspml.message.SpmlRequest;
import org.openspml.message.SpmlResponse;
import org.openspml.providers.one_c.OneCSpmlHandler;
import org.openspml.providers.one_c.SpmlClientFactory;
import org.openspml.server.SpmlHandler;
import org.openspml.util.SpmlException;

/**
 * @author <A href="mailto:abashev at gmail dot com">Alexey Abashev</A>
 * @version $Id$
 */
public class LocalClient implements SpmlClientFactory {
	@Override
	public SpmlClient getClient() {
		OneCSpmlHandler handler = new OneCSpmlHandler();
		
		return new LocalSpmlClient(handler);
	}
	
	private final class LocalSpmlClient extends SpmlClient {
		private final SpmlHandler handler;
		
		public LocalSpmlClient(SpmlHandler handler) {
			this.handler = handler;
		}

		@Override
		public SpmlResponse request(SpmlRequest request) throws SpmlException {
			return handler.doRequest(request);
		}
	}
}
